package bubbleSort;

import shared.Buffer;
import shared.MyComparable;
import shared.MyStop;
import shared.SortInput;
import shared.SortInputVisitor;

/**
 * The NoSorterStarted class is a state of a BubbleSorter that represents that no other sorter has been started.
 */
public class NoSorterStarted<T extends Comparable<? super T>> extends BubbleSorterState<T>{

	public NoSorterStarted(final BubbleSorter<T> bubbleSorter) {
		super(bubbleSorter);
	}

	@Override
	public Buffer<T> getResult() {
		final Buffer<T> result = new Buffer<T>();
		while(!this.getBubbleSorter().getOutputBuffer().isEmpty()){
			final SortInput<T> input = this.getBubbleSorter().getOutputBuffer().get();
			input.accept(new SortInputVisitor<T>() {

				@Override
				public void visit(final MyComparable<T> myComparable) {
					result.put(myComparable.getComparable());
				}

				@Override
				public void visit(final MyStop<T> myStop) {
					
				}
			});
		}
		return result;
	}

	@Override
	public void accept(final BubbleSorterStateVisitor<T> visitor) {
		visitor.visit(this);
	}
}
